﻿#define _CRT_SECURE_NO_WARNINGS 1

//练习5
#include <stdio.h>

//unsigned char的取值范围是0~255

unsigned char i = 0;
int main()
{
	for (i = 0; i <= 255; i++)
	{
		printf("hello world\n");//死循环
	}
	return 0;
}



#include <stdio.h>
#include <windows.h>
int main()
{
	unsigned int i;//>=0
	for (i = 9; i >= 0; i--)
	{
		printf("%u\n", i);//恒成立
		Sleep(1000);
	}
	return 0;
}



//练习6
#include <stdio.h>
//X86环境 小端字节序

int main()
{
	int a[4] = { 1, 2, 3, 4 };
	int* ptr1 = (int*)(&a + 1);//4
	int* ptr2 = (int*)((int)a + 1);//0x0012ff40 + 1 = 0x0012ff41
	printf("%x,%x", ptr1[-1], *ptr2);
	//		           4      0x02 00 00 00
	printf("%#x,%#x", ptr1[-1], *ptr2);
	return 0;
}



//浮点数在内存中的存储
//
//V = (−1)^S * M * 2^E
//
#include <stdio.h>
int main()
{
	int n = 9;
	float* pFloat = (float*)&n;
	printf("n的值为：%d\n", n);//9
	printf("*pFloat的值为：%f\n", *pFloat);//0.000000
	*pFloat = 9.0;
	printf("num的值为：%d\n", n);//1091567616
	printf("*pFloat的值为：%f\n", *pFloat);//9.000000

	return 0;
}

int main()
{
	//5.5
	float f = 5.5f;
	//5.5
	//101.1
	//1.011*2^2
	//(-1)^0 * 1.011 * 2^2
	//S=0
	//M=1.011
	//E=2  2 + 127 = 129
	//
	//0 10000001 01100000000000000000000
	//0100 0000 1011 0000 0000 0000 0000 0000
	//40 B0 00 00
	//
	return 0;
}

//如果小数点后的位太多，就可能导致浮点数在内存中无法精确地保存
//3.14 - 3.13995962
int main()
{
	float f1 = 0.4554f;
	printf("%f\n", f1);

	float f2 = 0.33333f;
	printf("%f\n", f2);

	return 0;
}



struct Book
{
	char name[20];
	char author[20];
	float price;
	char id[13];
}b3, b4;//全局变量

struct Book b2;//全局变量

int main()
{
	struct Book b1;//局部变量
	struct Book arr[5];//数组

	return 0;
}



struct Book
{
	char name[20];
	char author[20];
	float price;
	char id[13];
};

int main()
{
	struct Book b1 = { "电子技术基础","康华光、张林",67.00,"TD96005" };//局部变量
	struct Book b2 = { .id = "TD96005",.author = "康华光、张林",.name = "电子技术基础" ,.price = 67.00 };
	//. ->

	return 0;
}

//匿名结构体类型
//struct 
//{
//	char c;
//	int i;
//	double d;
//};
// 
//int main()
//{
//	struct S s;
//
//	return 0;
//}



struct 
{
	char c;
	int i;
	double d;
}s = { 'x',100,3.14 };

int main()
{
	printf("%c %d %f\n", s.c, s.i, s.d);

	return 0;
}


typedef struct 
{
	char c;
	int i;
	double d;
}S;

int main()
{
	S s;

	return 0;
}



//链表

typedef struct Node
{
	int data;//数据
	struct Node* next;//指针
}Node;

typedef struct Node Node;

int main()
{
	struct Node n1;
	Node n2;

	return 0;
}



//错误
typedef struct Node
{
	int data;//数据
	Node* next;//指针
}Node;



struct S
{
	char c1;
	int i;
	double c2;
};

int main()
{
	struct S s = { 0 };
	printf("%zd\n", sizeof(s));//?

	return 0;
}